
The Bottom-up Building of a Language for SUBLEQ 
with Text Macros

Andrew Davison, ad@coe.psu.ac.th, April 2026


Tools:
------
* subleq.py   - the Subleq assembler and interpreter
* listTri.py  - list ".tri" file
* toAscii.py  - convert a string to ASCII values
                (used for hello1.imp and hello2.imp)
* sx.bat      - batch file combining assembly and execution
* msx.bat     - batch file combining macro expansion,
                assembly and execution

Usage:
------
> python subleq.py asm XXX.asm 
> python subleq.py run XXX.tri
> python subleq.py trace XXX.tri

> python listTri.py XXX.tri

> sx XXX.asm
> msx XXX.imp

> m4 -d <text-file containing macros>
I use the version of m4 available in Gow
(https://github.com/bmatzelle/gow)



Triplet (.tri) Example
----------------------
* cycle1.tri  - infinite cycle between two triplets


Assembly (.asm) Examples
------------------------
cycle2.asm, cycle3.asm   - assembly versions of cycle1.tri
   - cycle3 prints the changing b value
add1.asm, add2.asm       - addition of two numbers
hi1.asm, hi2.asm         - print "Hi"


M4 Examples   (simple m4 macros)
-----------
* examples.m4
* myDefs.m4 and defsTest.txt
* quotes.imp


Imperative Lang (.imp) Examples  
-------------------------------
These use the macros defined in 
* defs.m4
to translate the high-level language down to ".asm" form

* add3.imp     - addition of two numbers
* addSub.imp   - addition and subtraction
* hi3.imp, hi4.imp  - print "Hi"

* if.imp  - if-test
* zeroTest.imp   - test of isZero() macro

* sum.imp   - sum 1 to i using a loop
* fib.imp   - print n terms of the Fibonacci seq
* cycle4.imp  - infinite cycle again

* hello1.imp, hello2.imp   - hello world using a loop
   - ".imp" version of code at https://esolangs.org/wiki/Subleq

* absTest.imp    - test of abs() macro
* multiply.imp   - three versions of multiple()
* fact.imp       - factorial using multiply() in a loop

* gosubTest.imp  - test of GOSUB/RETURN implementation
* sumG.imp       - call sum() three times
* factG.imp      - call fact() twice


Basic to C 
-----------
BASIC to C converter written by Peter van Eerten
(https://www.basic-converter.org/m4basic/)
* basic.m4
* fact.m4b  -- calculates 5! using fact()

Usage:
  m4 -d basic.m4  fact.m4b
  m4 -d basic.m4  fact.m4b | indent -br -i2 -l70 -nlp
